/**
 * 使用装饰器模拟超快网络请求
 *  ts 结合泛型 结合接口type  结合类 结合装饰器 可以给我们非常舒适的开发体验
 */
{
	type UserType = {
		username: string
		status: number
	}

	const RequestDecorator = (url: string): MethodDecorator => {
		return (
			target: Object,
			propertyKey: string | symbol,
			descriptor: PropertyDescriptor
		) => {
			console.log('请求的地址是：', url)
			let method = descriptor.value
			new Promise<UserType[]>(resolve => {
				setTimeout(() => {
					resolve([
						{ username: 'jimmy', status: 1 },
						{ username: 'xuexue', status: 1 },
						{ username: 'yj', status: 1 },
					])
				}, 2000)
			}).then(res => {
				method(res)
			})
		}
	}

	class User {
		@RequestDecorator('http://www.jimmyxuexue.top')
		public all(users: UserType[]) {
			console.log(users)
		}
	}
}
